package com.example.dnfgamercommunitybackend.controller;

import com.example.dnfgamercommunitybackend.entity.Account;
import com.example.dnfgamercommunitybackend.service.AccountService;
import org.springframework.http.HttpRequest;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
public class AccountController {
    @Resource
    private AccountService accountService;
    @PostMapping("/user/register")
    public String register(@RequestBody Account account){
        return accountService.register(account);
    }

    @PreAuthorize("hasAuthority('user:update_profile')")
    @PostMapping("/user/updateProfile")
    public String updateProfile(@RequestBody Account account, HttpServletRequest httpServletRequest){
        String token = httpServletRequest.getHeader("Authorization");
        return accountService.updateProfile(account,token);
    }

    @PreAuthorize("hasAuthority('user:profile_get_profile')")
    @GetMapping("/user/getProfile")
    public String getProfile(HttpServletRequest request){
        return accountService.getProfile(request.getHeader("Authorization"));
    }
}
